package com.aneliya.model;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

public class Message implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private MessageType messageType = MessageType.TEXT;
	public MessageType getMessageType() {
		return messageType;
	}
	public void setMessageType(MessageType messageType) {
		this.messageType = messageType;
	}
	
	private String username;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	
	private Object message;
	public Object getMessage() {
		return message;
	}
	public void setMessage(Object message) {
		this.message = message;
	}
	
	private Date date;
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	
	private UUID token;
	public UUID getToken() {
		return token;
	}
	public void setToken(UUID token) {
		this.token = token;
	}

	public Message(String username, Object message, Date date) {
		this.username = username;
		this.message = message;
		this.date = date;
		this.token = UUID.randomUUID();
	}
	
	public Message(String username, Object message) {
		this.username = username;
		this.message = message;
		this.token = UUID.randomUUID();
	}
	
	public boolean equals(Object obj) {
		if (obj instanceof Message) {
			Message compareMessage = (Message) obj;
			return message != null && message.equals(compareMessage.message) && 
				username != null && username.equals(compareMessage.username) && 
				date != null && date.equals(compareMessage.date) && 
				token != null && token.equals(compareMessage.token);
		}
		return false;
	}
	
	public int hashCode() {
		return message.hashCode() + 
			username.hashCode() + 
			date.hashCode() +
			token.hashCode();
	}
	
}
